package br.com.news.service;

import java.util.List;
import javax.inject.Inject;
import javax.inject.Named;
import br.com.news.utils.business.exception.BusinessException;
import br.com.news.utils.business.interfaces.INoticiaBusiness;
import br.com.news.utils.database.beans.NoticiaBean;
import br.com.news.utils.service.exception.ServiceException;
import br.com.news.utils.service.interfaces.INoticiaService;

@Named
public class NoticiaService implements INoticiaService{


	@Inject
	private INoticiaBusiness noticiaBusiness;

	@Override
	public List<NoticiaBean> findAll() throws ServiceException {
		try {
			return noticiaBusiness.findAll();
		} catch (BusinessException e) {
			throw new ServiceException(e);
		}
	}

	@Override
	public List<NoticiaBean> lastNews(int qntNoticias,long idNoticia, long idCategoria) throws ServiceException{
		try {
			return noticiaBusiness.lastNews(qntNoticias,idNoticia, idCategoria);
		} catch (BusinessException e) {
			throw new ServiceException(e);
		}
	}
	
	@Override
	public List<NoticiaBean> lastNews(long idNoticia, long idCategoria) throws ServiceException{
		try {
			return noticiaBusiness.lastNews(idNoticia, idCategoria);
		} catch (BusinessException e) {
			throw new ServiceException(e);
		}
	}

	@Override
	public Long save(NoticiaBean noticiaBean) throws ServiceException {
		try {
			return noticiaBusiness.save(noticiaBean);
		} catch (BusinessException e) {
			throw new ServiceException(e);
		}
	}
	
	@Override
	public void update(NoticiaBean noticiaBean) throws ServiceException {
		try {
			noticiaBusiness.update(noticiaBean);
		} catch (BusinessException e) {
			throw new ServiceException(e);
		}
	}

	@Override
	public boolean existeNoticia(NoticiaBean noticiaBean) {
		return noticiaBusiness.existeNoticia(noticiaBean);
	}
	
	@Override
	public NoticiaBean findNoticiaById(Long id) throws ServiceException {
		try {
			return noticiaBusiness.findNoticiaById(id);
		} catch (BusinessException e) {
			throw new ServiceException(e);
		}
	}
	
	@Override
	public NoticiaBean findImageByIdNoticia(Long idNoticia) throws ServiceException {
		try {
			return noticiaBusiness.findImageByIdNoticia(idNoticia);
		} catch (BusinessException e) {
			throw new ServiceException(e);
		}
	}
	
	@Override
	public Long quantidadePaginas(long idCategoria) {
		return noticiaBusiness.quantidadePaginas(idCategoria);
	}
	
	@Override
	public List<NoticiaBean> findNoticiasPorPagina(int linha,Long idCategoria,int quantidade) {
		return noticiaBusiness.findNoticiasPorPagina(linha, idCategoria,quantidade);
	}
	
	@Override
	public List<NoticiaBean> buscaNoticiaPorNome(String nome) {
		return noticiaBusiness.buscaNoticiaPorNome(nome);
	}

	@Override
	public List<NoticiaBean> findByExample(NoticiaBean noticiaBean) {
		return noticiaBusiness.findByExample(noticiaBean);
	}

	@Override
	public String returnTextNew(long idNoticia) throws ServiceException {
		try {
			return noticiaBusiness.returnTextNew(idNoticia);
		} catch (BusinessException e) {
			throw new ServiceException(e);
		}
	}

}
